package com.amx.controller;

import com.alibaba.fastjson.JSON;
import com.amx.Pojo.User;
import com.amx.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@RestController
public class LoginController {

    @Autowired
    UserDao userDao;  // 拿到dao层操作数据库拿到的结果

    // .0@RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)；
    @RequestMapping("/login")
    public String login(@RequestBody User user){
        String flag = "error";
        User userRes = userDao.getUserByMessage(user.getUsername(), user.getPassword()); // 获取到数据库中
        if (userRes != null){
            flag = "true";
        }
        HashMap<String,Object> res = new HashMap<>();
        res.put("user",userRes);
        res.put("flag",flag);
        return JSON.toJSONString(res);
    }

}
